import axios from "axios"
import ChartCreater,{EChartType,IAxisChartConfig,ChartConfigMgr,IRadarChartConfig} from "@/index";
import component1 from "./subComponents/component1";
import component4 from "./subComponents/component4";

import DataSource,{IDataSourceConfig} from "@dataSource/dataSource"
export default function(chartConfig:IAxisChartConfig|IRadarChartConfig){
    // function getData(params:any){
    //     params = chartConfig.defaultFilter || params;
    //     return  axios.get(chartConfig.dataSourceURL, params);
    // }

    function getData(params:any){
        return  axios.get("https://www.fastmock.site/mock/f0ae2cb1541305cefa1b7d31b3cc6d13/api/api/getDataList",params);
    }
    function getMateData(params:any){
        params = chartConfig.defaultMateFilter || params;
        return  axios.get(chartConfig.mateDataURL, params);
    }
    const chart1 = ChartCreater({...chartConfig},new DataSource({
        dataFn: getData,
        mateDataFn: getMateData
    }))
    chart1.create((chartTarget,dataSource,reRender,destroyMySelf)=>{
        if(chartTarget?.getConfig("chartType") == EChartType.AxisChart){
            component1(<ChartConfigMgr<IAxisChartConfig>>chartTarget,dataSource,reRender,destroyMySelf)
        }else if(chartTarget?.getConfig("chartType") == EChartType.RadarChart){
            component4(<ChartConfigMgr<IRadarChartConfig>>chartTarget,dataSource,reRender,destroyMySelf)
        }
    });

    return chart1;
};